<extend name="base"/>

<block name="main">
    <div class="set-box">
        <if condition="I('is_edit_pwd') == 0">
            <div class="sb-ts">当前为首次设置密码，默认密码为：{:I('default_pwd')}</div>
        </if>

        <div class="sb-nr">
            <label class="sbn-l">原密码：</label>
            <input type="password" placeholder="请输入原密码" placeholder-style="color:#aaa;" class="sbn-wb old_password"></input>
            <div class="clear"></div>
        </div>

        <div class="sb-nr">
            <label class="sbn-l">新密码：</label>
            <input type="password" placeholder="请输入新密码" placeholder-style="color:#aaa;" class="sbn-wb new_password"></input>
            <div class="clear"></div>
        </div>

        <div class="sb-nr">
            <label class="sbn-l">确认密码：</label>
            <input type="password" placeholder="请重复输入新密码" placeholder-style="color:#aaa;" class="sbn-wb re_password"></input>
            <div class="clear"></div>
        </div>

        <button class="sb-btn" onclick="setPassword()">确认</button>
    </div>
</block>

<block name="js">
    <script>
        function setPassword(){
            var uid = "{$Think.session.uid}";
            var old_password = $('.old_password').val();
            var new_password = $('.new_password').val();
            var re_password = $('.re_password').val();

            if(new_password !== re_password){
                layer.msg('新密码与确认密码不一致，请重新输入');
            }else{
                $.showLoading('请稍等');

                post_ajax('Apis/setPassword', {
                    uid: uid,
                    old_password: old_password,
                    new_password: new_password
                }, function (res) {
                    layer.msg(res.msg)

                    if(res.result == 1){
                        setTimeout(function (){
                            history.back(-1);
                        },1000)
                    }
                })
            }
        }
    </script>
</block>
